package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mapper.QuestionMapper;
import com.tanhua.model.domain.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/11/30 0:16
 */

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question findByUserId(Long userId) {

        LambdaQueryWrapper<Question> queueWrapper = new LambdaQueryWrapper<>();
        queueWrapper.eq(Question::getUserId, userId);
        Question question = questionMapper.selectOne(queueWrapper);
        return question;
    }

    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 根据用户id进行修改
     * @param question
     */
    @Override
    public void updateByUserId(Question question) {

        LambdaQueryWrapper<Question> queueWrapper = new LambdaQueryWrapper<>();
        queueWrapper.eq(Question::getUserId, question.getUserId());
        questionMapper.update(question, queueWrapper);
    }
}
